package com.gkwave.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class BusRegister extends Activity implements OnClickListener{
	
	protected static final String TAG = "BusRegister";

	private final int DIALOG_CITY= 0x01;
	private final int DIALOG_LOCATION = 0x02;
	private final int DIALOG_BPOINT = 0x03;
	
	private EditText mCity = null;
	private EditText mLocation = null;
	private EditText mBPoint = null;
	private EditText mMNumber = null;
	private EditText mEID = null;
	
	private Button mSubmit = null;
	
	private CharSequence[] mCity_list = {"Chennai", "Bangalore"};
	private CharSequence[] mLocation_list = {"Location1", "Location2"};
	private CharSequence[] mBPoint_list = {"Point1", "Point2"};
	
	private boolean mValid_city = false;
	private boolean mValid_location = false;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.bus_register);
		
		mCity = (EditText) findViewById(R.id.edit_city);
		mLocation = (EditText) findViewById(R.id.edit_location);
		mBPoint = (EditText) findViewById(R.id.edit_bpoint);
		mMNumber = (EditText) findViewById(R.id.edit_mobile);
		mEID = (EditText) findViewById(R.id.edit_eid);
		
		mLocation.setEnabled(false);
		mBPoint.setEnabled(false);
		
		mCity.setOnClickListener(this);
		mLocation.setOnClickListener(this);
		mBPoint.setOnClickListener(this);
		
		mSubmit = (Button) findViewById(R.id.submit_button);
		mSubmit.setOnClickListener(this);
	}

	@Override
	protected Dialog onCreateDialog(int id, Bundle args) {
		
		switch(id){
		case DIALOG_CITY:
            return new AlertDialog.Builder(BusRegister.this)
            .setTitle(R.string.city)
            .setItems(mCity_list, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                	Log.i(TAG,"DIALOG_CITY::onClick which:"+which);
                	CharSequence city = mCity_list[which];
                	mCity.setText(city);
                	mValid_city = true;
            		mLocation.setEnabled(true);
                }
            })
            .create();
		case DIALOG_LOCATION:
            return new AlertDialog.Builder(BusRegister.this)
            .setTitle(R.string.location)
            .setItems(mLocation_list, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                	Log.i(TAG,"DIALOG_CITY::onClick which:"+which);
                	CharSequence location = mLocation_list[which];
                	mLocation.setText(location);
                	mValid_location = true;
                	mBPoint.setEnabled(true);
                }
            })
            .create();
		case DIALOG_BPOINT:
            return new AlertDialog.Builder(BusRegister.this)
            .setTitle(R.string.b_point)
            .setItems(mBPoint_list, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                	Log.i(TAG,"DIALOG_CITY::onClick which:"+which);
                	CharSequence b_point = mBPoint_list[which];
                	mBPoint.setText(b_point);
                }
            })
            .create();
		default: return super.onCreateDialog(id, args); 
		}
		
	}

	public void onClick(View arg0) {
		int id = arg0.getId();
		switch(id){
		case R.id.edit_city:
			showDialog(DIALOG_CITY);
			break;
		case R.id.edit_location:
			showDialog(DIALOG_LOCATION);
			break;
		case R.id.edit_bpoint:
			showDialog(DIALOG_BPOINT);
			break;
		case R.id.submit_button:
			//String city = mCity.getText().toString().trim();
			break;
		}
	}

}
